/**
 * 
 */
package com.geekteam.manga.Utils;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.geekteam.manga.R;
import com.geekteam.manga.Utils.Constant.FontId;

/**
 * @author MtRol
 * 
 */
public class FontUtils {

	public static Typeface getTypeface(Context context, int fontId) {
		Typeface typeface = null;
		switch (fontId) {
		case FontId.BLACK:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Black.ttf");
			break;
		case FontId.BLACK_ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-BlackItalic.ttf");
			break;
		case FontId.BOLD:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Bold.ttf");
			break;
		case FontId.BOLD_CONDENSED:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-BoldCondensed.ttf");
			break;
		case FontId.BOLD_CONDENSED_ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-BoldCondensedItalic.ttf");
			break;
		case FontId.BOLD_ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-BoldItalic.ttf");
			break;
		case FontId.CONDENSED:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Condensed.ttf");
			break;
		case FontId.CONDENSED_ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-CondensedItalic.ttf");
			break;
		case FontId.ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Italic.ttf");
			break;
		case FontId.LIGHT:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Light.ttf");
			break;
		case FontId.LIGHT_ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-LightItalic.ttf");
			break;
		case FontId.MEDIUM:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Medium.ttf");
			break;
		case FontId.MEDIUM_ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-MediumItalic.ttf");
			break;
		case FontId.REGULAR:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Regular.ttf");
			break;
		case FontId.THIN:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-Thin.ttf");
			break;
		case FontId.THIN_ITALIC:
			typeface = Typeface.createFromAsset(context.getAssets(),
					"fonts/roboto/Roboto-ThinItalic.ttf");
			break;
		default:
			return null;
		}

		return typeface;
	}

	public static void setTypeface(Context context, View view, int fontId) {
		if (view instanceof TextView) {
			((TextView) view).setTypeface(getTypeface(context, fontId));
		}
	}

	public static void initAttributeSet(Context context, AttributeSet attrs,
			View view) {
		TypedArray fontTypeArray = context.getTheme().obtainStyledAttributes(
				attrs, R.styleable.GTextStyle, 0, 0);
		try {
			int fontId = fontTypeArray.getInt(
					R.styleable.GTextStyle_fontName, FontId.NONE);
			setTypeface(context, view, fontId);
		} finally {
			fontTypeArray.recycle();
		}
	}
}
